<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猫咖管理系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 全局样式 */
        :root {
            --primary-color: #D85D5D;
            --secondary-color: #9B7E46;
            --accent-color: #FFA384;
            --light-color: #F8F3EA;
            --dark-color: #333333;
            --success-color: #4CAF50;
            --error-color: #FF5252;
            --sale-color: #E74C3C;
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f9f9f9;
            color: var(--dark-color);
            line-height: 1.6;
        }

        .container {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* 顶部导航栏样式 */
        header {
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .header-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 0;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .logo-icon {
            width: 40px;
            height: 40px;
            background-color: var(--primary-color);
            border-radius: 50%;
            position: relative;
        }

        .logo-icon::after {
            content: '';
            position: absolute;
            top: -4px;
            left: -4px;
            width: 48px;
            height: 48px;
            border-radius: 50%;
            border: 1px solid rgba(216, 93, 93, 0.2);
        }

        .logo h1 {
            font-size: 24px;
            color: var(--primary-color);
        }

        nav ul {
            display: flex;
            list-style: none;
            gap: 25px;
        }

        nav a {
            text-decoration: none;
            color: var(--dark-color);
            font-weight: 500;
            padding: 8px 12px;
            border-radius: 4px;
            transition: var(--transition);
            position: relative;
        }

        nav a:hover,
        nav a.active {
            color: var(--primary-color);
        }

        nav a::after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 0;
            width: 0;
            height: 2px;
            background-color: var(--primary-color);
            transition: var(--transition);
        }

        nav a:hover::after,
        nav a.active::after {
            width: 100%;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .user-info span {
            font-weight: 500;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-weight: 500;
            transition: var(--transition);
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: #c74d4d;
        }

        /* 轮播图样式 */
        .hero {
            background: linear-gradient(135deg, var(--light-color) 0%, #f9f9f9 100%);
            padding: 60px 0;
            position: relative;
            overflow: hidden;
        }

        .slider {
            position: relative;
            max-width: 1000px;
            height: 400px;
            margin: 0 auto;
            overflow: hidden;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
        }

        .slide {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            transition: opacity 1s ease;
            background-size: cover;
            background-position: center;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .slide.active {
            opacity: 1;
        }

        .slide-content {
            background-color: rgba(255, 255, 255, 0.85);
            padding: 30px;
            border-radius: 8px;
            text-align: center;
            max-width: 80%;
        }

        .slide-content h2 {
            font-size: 32px;
            margin-bottom: 15px;
            color: var(--primary-color);
        }

        .slide-content p {
            font-size: 18px;
            margin-bottom: 20px;
        }

        .slider-nav {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 10px;
            z-index: 10;
        }

        .slider-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.5);
            cursor: pointer;
            transition: var(--transition);
        }

        .slider-dot.active {
            background-color: white;
        }

        .slider-btn {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background-color: rgba(0, 0, 0, 0.3);
            color: white;
            border: none;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            font-size: 24px;
            cursor: pointer;
            z-index: 10;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: var(--transition);
        }

        .slider-btn:hover {
            background-color: rgba(0, 0, 0, 0.5);
        }

        .prev-btn {
            left: 20px;
        }

        .next-btn {
            right: 20px;
        }

        /* 主要内容区域 */
        .main-content {
            padding: 60px 0;
        }

        .section-title {
            text-align: center;
            margin-bottom: 40px;
            position: relative;
        }

        .section-title h2 {
            font-size: 32px;
            color: var(--primary-color);
            display: inline-block;
            margin-bottom: 15px;
        }

        .section-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 3px;
            background-color: var(--secondary-color);
        }

        .features {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 60px;
        }

        .feature-card {
            background-color: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            transition: var(--transition);
        }

        .feature-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
        }

        .feature-img {
            height: 200px;
            background-size: cover;
            background-position: center;
        }

        .feature-content {
            padding: 20px;
        }

        .feature-content h3 {
            font-size: 20px;
            margin-bottom: 10px;
            color: var(--dark-color);
        }

        .feature-content p {
            color: #666;
            margin-bottom: 15px;
        }

        .feature-content .btn {
            display: inline-block;
            padding: 8px 16px;
            background-color: var(--primary-color);
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-weight: 500;
            transition: var(--transition);
        }

        .feature-content .btn:hover {
            background-color: #c74d4d;
        }

        /* 限时秒杀样式 */
        .seckill-section {
            background-color: white;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            margin-bottom: 40px;
        }

        .seckill-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid var(--light-color);
        }

        .seckill-title {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .seckill-title h2 {
            color: var(--sale-color);
            font-size: 24px;
        }

        .seckill-title i {
            color: var(--sale-color);
            font-size: 28px;
        }

        .countdown {
            background-color: var(--sale-color);
            color: white;
            padding: 8px 16px;
            border-radius: 20px;
            font-weight: 600;
            font-size: 18px;
        }

        .seckill-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
        }

        .seckill-item {
            background-color: var(--light-color);
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
            transition: var(--transition);
            position: relative;
        }

        .seckill-item:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 15px rgba(0,0,0,0.15);
        }

        .seckill-badge {
            position: absolute;
            top: 10px;
            right: 10px;
            background-color: var(--sale-color);
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 14px;
            font-weight: 600;
            z-index: 2;
        }

        .seckill-img {
            height: 180px;
            background-size: cover;
            background-position: center;
            position: relative;
        }

        .seckill-img::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.1) 100%);
        }

        .seckill-content {
            padding: 15px;
        }

        .seckill-content h3 {
            font-size: 18px;
            margin-bottom: 10px;
            color: var(--dark-color);
        }

        .seckill-content p {
            color: #666;
            font-size: 14px;
            margin-bottom: 10px;
            min-height: 60px;
        }

        .price-container {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 15px;
        }

        .original-price {
            text-decoration: line-through;
            color: #999;
            font-size: 16px;
        }

        .seckill-price {
            color: var(--sale-color);
            font-size: 20px;
            font-weight: 700;
        }

        .seckill-btn {
            width: 100%;
            padding: 10px;
            background-color: var(--sale-color);
            color: white;
            border: none;
            border-radius: 4px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .seckill-btn:hover {
            background-color: #c0392b;
        }

        .seckill-btn:disabled {
            background-color: #95a5a6;
            cursor: not-allowed;
        }

        .seckill-btn i {
            font-size: 16px;
        }

        .sold-out {
            background-color: #7f8c8d;
        }

        /* 页脚样式 */
        footer {
            background-color: var(--dark-color);
            color: white;
            padding: 40px 0 20px;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 30px;
            margin-bottom: 30px;
        }

        .footer-column h3 {
            font-size: 20px;
            margin-bottom: 20px;
            position: relative;
            padding-bottom: 10px;
        }

        .footer-column h3::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 2px;
            background-color: var(--primary-color);
        }

        .footer-links {
            list-style: none;
        }

        .footer-links li {
            margin-bottom: 10px;
        }

        .footer-links a {
            color: #bbb;
            text-decoration: none;
            transition: var(--transition);
        }

        .footer-links a:hover {
            color: white;
            padding-left: 5px;
        }

        .contact-info {
            color: #bbb;
        }

        .contact-info p {
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .copyright {
            text-align: center;
            padding-top: 20px;
            border-top: 1px solid #444;
            color: #bbb;
            font-size: 14px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .header-container {
                flex-direction: column;
                gap: 15px;
            }

            nav ul {
                flex-wrap: wrap;
                justify-content: center;
            }

            .slider {
                height: 300px;
            }

            .slide-content {
                padding: 15px;
            }

            .slide-content h2 {
                font-size: 24px;
            }

            .slide-content p {
                font-size: 16px;
            }

            .seckill-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<header>
    <div class="container header-container">
        <div class="logo">
            <div class="logo-icon"></div>
            <h1>猫咖管理系统</h1>
        </div>

        <nav>
            <ul>
                <li><a href="index.html" class="active">首页</a></li>
                <li><a href="cat.html">猫咪预约</a></li>
                <li><a href="cafe.html">咖啡购买</a></li>
                <li><a href="center.html">个人中心</a></li>
                <li><a href="message.html">留言板</a></li>
                <li><a href="orders.html">订单信息</a></li>
                <li><a href="booking.html">预约信息</a></li>
            </ul>
        </nav>

        <!-- 顶部导航栏的用户信息部分 -->
        <div class="user-info">
            <!-- 这里将显示用户名和角色信息 -->
            <span id="user-display">未登录</span>
            <button class="btn btn-primary" id="logout-btn">退出</button>
        </div>
    </div>
</header>

<!-- 轮播图区域 -->
<section class="hero">
    <div class="slider">
        <div class="slide active" style="background-image: url('https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?q=80&w=1687&auto=format&fit=crop')">
            <div class="slide-content">
                <h2>欢迎来到猫咖管理系统</h2>
                <p>撸猫与咖啡的完美碰撞</p>
<!--                <button class="btn btn-primary">了解更多</button>-->
            </div>
        </div>

        <div class="slide" style="background-image: url('https://images.unsplash.com/photo-1494256997604-768d1f608cac?q=80&w=1529&auto=format&fit=crop')">
            <div class="slide-content">
                <h2>可爱的猫咪们</h2>
                <p>我们拥有20多个品种的可爱猫咪</p>
<!--                <button class="btn btn-primary">撸猫预约</button>-->
            </div>
        </div>

        <div class="slide" style="background-image: url('https://images.unsplash.com/photo-1495474472287-4d71bcdd2085?q=80&w=1470&auto=format&fit=crop')">
            <div class="slide-content">
                <h2>精品咖啡</h2>
                <p>品尝我们精心调制的特色咖啡</p>
<!--                <button class="btn btn-primary">查看咖啡菜单</button>-->
            </div>
        </div>

        <button class="slider-btn prev-btn">❮</button>
        <button class="slider-btn next-btn">❯</button>

        <div class="slider-nav">
            <div class="slider-dot active"></div>
            <div class="slider-dot"></div>
            <div class="slider-dot"></div>
        </div>
    </div>
</section>

<!-- 主要内容区域 -->
<section class="main-content">
    <div class="container">
        <div class="section-title">
            <h2>特色服务</h2>
        </div>

        <div class="features">
            <div class="feature-card">
                <div class="feature-img" style="background-image: url('https://images.unsplash.com/photo-1573865526739-10659fec78a5?q=80&w=1615&auto=format&fit=crop')"></div>
                <div class="feature-content">
                    <h3>猫咪预约</h3>
                    <p>预约你心仪的猫咪，体验撸猫的乐趣</p>
                    <a href="cat.html" class="btn">查看详情</a>
                </div>
            </div>

            <div class="feature-card">
                <div class="feature-img" style="background-image: url('https://images.unsplash.com/photo-1514432324607-a09d9b4aefdd?q=80&w=1471&auto=format&fit=crop')"></div>
                <div class="feature-content">
                    <h3>咖啡购买</h3>
                    <p>各种各样的咖啡供你选择，让您的猫咖时光更加惬意</p>
                    <a href="cafe.html" class="btn">查看详情</a>
                </div>
            </div>

            <div class="feature-card">
                <div class="feature-img" style="background-image: url('https://images.unsplash.com/photo-1542556398-95fb5b9f9b48?q=80&w=1470&auto=format&fit=crop')"></div>
                <div class="feature-content">
                    <h3>订单管理系统</h3>
                    <p>查看客户订单，高效解决订单纠纷</p>
                    <a href="orders.html" class="btn">查看详情</a>
                </div>
            </div>
        </div>

        <!-- 限时秒杀区域 -->
        <div class="seckill-section">
            <div class="seckill-header">
                <div class="seckill-title">
                    <i class="fas fa-bolt"></i>
                    <h2>限时秒杀</h2>
                </div>
                <div class="countdown">剩余时间: <span id="countdown-timer">00:12:45</span></div>
            </div>

            <div class="seckill-grid" id="seckill-grid">
                <!-- 秒杀商品将通过JS动态加载 -->
            </div>
        </div>
    </div>
</section>

<!-- 页脚 -->
<footer>
    <div class="container">
        <div class="footer-content">
            <div class="footer-column">
                <h3>关于我们</h3>
                <p>猫咖管理系统致力于为猫咪咖啡馆提供专业的管理解决方案，帮助店主高效管理猫咪、咖啡和顾客信息。</p>
            </div>

            <div class="footer-column">
                <h3>快速链接</h3>
                <ul class="footer-links">
                    <li><a href="index.html">首页</a></li>
                    <li><a href="cat.html">猫咪信息</a></li>
                    <li><a href="cafe.html">咖啡菜单</a></li>
                    <li><a href="">在线预订</a></li>
                    <li><a href="center.html">个人中心</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>联系方式</h3>
                <div class="contact-info">
                    <p>地址：广东科技学院</p>
                    <p>电话：666666</p>
                    <p>邮箱：666666.com</p>
                    <p>营业时间：10:00-18:00</p>
                </div>
            </div>
        </div>

        <div class="copyright">
            <p>© 2025 猫咖管理系统 版权所有 | 设计开发：会非的杨</p>
        </div>
    </div>
</footer>

<script>
    //从localStorage获取用户信息
    // 页面加载完成后执行
    document.addEventListener('DOMContentLoaded', function() {
        // 从localStorage获取用户信息
        const username = localStorage.getItem('username');
        const role = localStorage.getItem('role');

        // 获取显示用户信息的元素
        const userDisplay = document.getElementById('user-display');

        // 如果有用户信息，显示在导航栏
        if (username) {
            // 根据角色显示不同的文本
            const roleText = role === 'admin' ? '管理员' : '普通用户';
            userDisplay.textContent = `${roleText}：${username}`;

            // 添加角色图标
            userDisplay.innerHTML = `
            <i class="fas fa-user-circle"></i>
            <span class="username-text">${username}</span>
            <span class="role-badge">${roleText}</span>
        `;
        } else {
            userDisplay.textContent = "未登录";
        }

        // 退出按钮功能
        const logoutBtn = document.getElementById('logout-btn');
        logoutBtn.addEventListener('click', function() {
            // 清除存储的用户信息
            localStorage.removeItem('username');
            localStorage.removeItem('role');

            // 提示用户并跳转到登录页
            alert('您已成功退出');
            window.location.href = 'login.html'; // 替换为您的登录页面
        });
    });

    // 轮播图功能
    document.addEventListener('DOMContentLoaded', function() {
        const slides = document.querySelectorAll('.slide');
        const dots = document.querySelectorAll('.slider-dot');
        const prevBtn = document.querySelector('.prev-btn');
        const nextBtn = document.querySelector('.next-btn');
        let currentSlide = 0;
        let slideInterval;

        // 初始化轮播
        function initSlider() {
            if (slides.length === 0) return;

            // 显示第一张幻灯片
            slides[currentSlide].classList.add('active');
            dots[currentSlide].classList.add('active');

            // 设置自动播放
            startSlideShow();
        }

        // 开始自动轮播
        function startSlideShow() {
            slideInterval = setInterval(() => {
                goToSlide((currentSlide + 1) % slides.length);
            }, 5000);
        }

        // 跳转到指定幻灯片
        function goToSlide(n) {
            slides[currentSlide].classList.remove('active');
            dots[currentSlide].classList.remove('active');

            currentSlide = (n + slides.length) % slides.length;

            slides[currentSlide].classList.add('active');
            dots[currentSlide].classList.add('active');
        }

        // 下一张
        function nextSlide() {
            clearInterval(slideInterval);
            goToSlide(currentSlide + 1);
            startSlideShow();
        }

        // 上一张
        function prevSlide() {
            clearInterval(slideInterval);
            goToSlide(currentSlide - 1);
            startSlideShow();
        }

        // 导航点点击事件
        dots.forEach((dot, index) => {
            dot.addEventListener('click', () => {
                clearInterval(slideInterval);
                goToSlide(index);
                startSlideShow();
            });
        });

        // 按钮事件监听
        prevBtn.addEventListener('click', prevSlide);
        nextBtn.addEventListener('click', nextSlide);

        // 初始化轮播图
        initSlider();

        // 导航菜单激活状态
        const navLinks = document.querySelectorAll('nav a');
        navLinks.forEach(link => {
            link.addEventListener('click', function(e) {
                // 移除所有active类
                navLinks.forEach(l => l.classList.remove('active'));
                // 为当前点击的链接添加active类
                this.classList.add('active');
            });
        });
    });

    // 限时秒杀功能
    document.addEventListener('DOMContentLoaded', function() {
        async function fetchCats() {
            try {
                const response = await fetch('/catcafe/seckillcats');
                if (!response.ok) throw new Error("获取猫咪信息失败");
                const data = await response.json();
                return data.data || []; // 直接返回 data 或空数组
            } catch (error) {
                console.error(error);
                return [];
            }
        }

        async function fetchCoffees() {
            try {
                const response = await fetch('/catcafe/seckillcoffees');
                if (!response.ok) throw new Error("获取咖啡信息失败");
                const data = await response.json();
                return data.data || []; // 直接返回 data 或空数组
            } catch (error) {
                console.error(error);
                return [];
            }
        }


        // 渲染秒杀商品
        async function renderSeckillItems() {
            const seckillGrid = document.getElementById('seckill-grid');
            const cats = await fetchCats();
            const coffees = await fetchCoffees();

            // 合并商品并添加 type 字段
            const seckillItems = [
                ...cats.map(item => ({ ...item, type: 'cat' })),
                ...coffees.map(item => ({ ...item, type: 'coffee' }))
            ];

            // 清空容器
            seckillGrid.innerHTML = '';

            // 渲染每个商品
            seckillItems.forEach(item => {
                const seckillPrice = Math.floor(item.price / 2);
                const isCat = item.type === 'cat';

                const seckillItem = document.createElement('div');
                seckillItem.className = 'seckill-item';
                seckillItem.innerHTML = `
            <div class="seckill-badge">限时5折</div>
            <div class="seckill-img" style="background-image: url('${item.image}')"></div>
            <div class="seckill-content">
                <h3>${item.name}</h3>
                <p>${item.description}</p>
                <div class="price-container">
                    <span class="original-price">原价: ¥${item.price}</span>
                    <span class="seckill-price">秒杀价: ¥${seckillPrice}</span>
                </div>
                <button class="seckill-btn" data-id="${item.id}" data-type="${isCat ? 'cat' : 'coffee'}">
                    <i class="${isCat ? 'fas fa-paw' : 'fas fa-coffee'}"></i>
                    ${isCat ? '立即预约' : '立即购买'}
                </button>
            </div>
        `;

                seckillGrid.appendChild(seckillItem);
            });

            // 添加按钮事件监听
            addSeckillEventListeners();
        }


        function addSeckillEventListeners() {
            const seckillBtns = document.querySelectorAll('.seckill-btn');

            seckillBtns.forEach(btn => {
                btn.addEventListener('click', function () {
                    const itemId = this.getAttribute('data-id');
                    const itemType = this.getAttribute('data-type');

                    // 检查用户是否已登录
                    const username = localStorage.getItem('username');
                    if (!username) {
                        alert('请先登录后再进行秒杀操作！');
                        window.location.href = 'login.html';
                        return;
                    }

                    // 触发真实请求
                    sendRealSeckillRequest(itemId, itemType, this);
                });
            });
        }


        // 发送真实的秒杀购买/预约请求
        // 发送真实的秒杀购买/预约请求
        async function sendRealSeckillRequest(itemId, itemType, button) {
            const userid = localStorage.getItem('userId');

            // 为每个商品生成唯一标识
            const purchasedKey = `seckill_${userid}_${itemId}`;

            // // 如果已经购买过该商品，直接返回
            // if (localStorage.getItem(purchasedKey)) {
            //     alert('您已经参与过该商品的秒杀活动，每个商品限购一次！');
            //     button.disabled = true;
            //     button.textContent = itemType === 'cat' ? '已预约' : '已售罄';
            //     button.classList.add('sold-out');
            //     return;
            // }
            if (sessionStorage.getItem(purchasedKey)) {
                alert('您已经参与过该商品的秒杀活动，每个商品限购一次！');
                button.disabled = true;
                button.textContent = itemType === 'cat' ? '已预约' : '已售罄';
                button.classList.add('sold-out');
                return;
            }

// 购买后标记为已购买
            sessionStorage.setItem(purchasedKey, 'true');


            let apiUrl;
            let method;
            let requestBody;

            if (itemType === 'cat') {
                // 预约猫咪 - 带预约时间字段
                apiUrl = '/catcafe/bookingsseckill'; // 替换为你的后端接口地址
                method = 'POST';

                const reserveTime = new Date().toISOString(); // 当前时间 ISO 格式
                requestBody = {
                    userId: userid,
                    catId: itemId,
                    reserveTime: reserveTime
                };

            } else {
                // 购买咖啡 - 不带预约时间
                apiUrl = '/catcafe/ordersseckill'; // 替换为你的后端接口地址
                method = 'POST';

                requestBody = {
                    userId: userid,
                    coffeeId: itemId
                };
            }

            try {
                const response = await fetch(apiUrl, {
                    method: method,
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(requestBody)
                });

                if (!response.ok) {
                    throw new Error(`操作失败: ${response.statusText}`);
                }

                const result = await response.json();
                console.log(result); // 打印服务器响应

                // 标记用户已购买该商品
                localStorage.setItem(purchasedKey, 'true');

                // 禁用按钮并更新状态
                button.disabled = true;
                button.textContent = itemType === 'cat' ? '已预约' : '已售罄';
                button.classList.add('sold-out');

                // 提示用户操作成功
                alert(`操作成功！您已成功${itemType === 'cat' ? '预约' : '购买'}该商品`);
            } catch (error) {
                console.error(error);
                alert('操作过程中出现错误，请稍后再试');
            }
        }




        // 初始化倒计时
        function initCountdown() {
            const countdownElement = document.getElementById('countdown-timer');

            // 设置秒杀结束时间（当前时间+12小时）
            const endTime = new Date();
            endTime.setHours(endTime.getHours() + 12);

            // 更新倒计时
            function updateCountdown() {
                const now = new Date();
                const diff = endTime - now;

                if (diff <= 0) {
                    countdownElement.textContent = '秒杀已结束';
                    return;
                }

                // 计算小时、分钟、秒
                const hours = Math.floor(diff / (1000 * 60 * 60));
                const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
                const seconds = Math.floor((diff % (1000 * 60)) / 1000);

                // 格式化时间
                countdownElement.textContent = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
            }

            // 初始更新
            updateCountdown();

            // 每秒更新一次
            setInterval(updateCountdown, 1000);
        }

        // 初始化限时秒杀功能
        renderSeckillItems();
        initCountdown();
    });
</script>
</body>
</html>